<template>
  <wrap title="身份验证" oneScreen>
    <div slot="page">
      <div class='fill-box margin-bottom'>
        <div class="bg">
          <img src='../../assets/images/verify.png'>
          <h6 class="tip">请确保拍摄本人</h6>
        </div>
        <div class="fill-btn-box">
          <a class="fill-btn red-bg flex flex-center grey-9-bg" @click="faceReconize()">
            <span class="light font-18" >采集本人人脸</span>
          </a>
        </div>
        <!-- <a href="javascript:;" class="next-btn blue" @click="skip()">跳过该步骤</a>  -->
      </div>
    </div>
  </wrap>
</template>
<script>
  import wrap from '../../components/wrap.vue'
  export default {
    components: {wrap},
    data () {
      return {
        autoPassFlag: false,
        userInfo: {
          name: '',
          idcard: ''
        }
      }
    },
    created () {
      const self = this
      self.$api.fill.getZmxyAuthInfo().then(res => {
        if (res.code === 0) {
          let data = res.data
          self.userInfo.name = data.nameReal
          self.userInfo.idcard = data.idCardReal
        } else {
          self.$Toast(res.userMsg ? res.userMsg : res.msg ? res.msg : res.code)
        }
      })
      this.queryAuthResult()
    },
    methods: {
      faceReconize () {
        const self = this
         /* eslint-disable no-undef */
        if (self.$store.state.inAPP && jiujiJsBridge && jiujiJsBridge.faceRecognition) {
          var data = {
            name: self.userInfo.name,
            idcard: self.userInfo.idcard
          }
          jiujiJsBridge.faceRecognition(data, (res) => {
            if (res === '人脸认证成功') {
              // MessageBox.confirm('确定执行此操作?').then(action => {
              this.getSignUrl()
              // })
            } else {
              self.$MessageBox.alert('人脸验证失败')
            }
          })
        } else {
          self.$MessageBox.confirm('必须在app中打开,前往下载app？').then(action => {
            window.location.href = 'https://m.9ji.com/download-app'
          })
        }
      },
      queryAuthResult () {
        const self = this
        self.$api.fill.queryAuthResult().then(res => {
          console.log(res)
        })
      },
      getSignUrl () {
        const self = this
        self.$Indicator.open()
        self.$api.sign.getSignUrl().then(res => {
          self.$Indicator.close()
          if (res.code === 0) {
            let url = res.data
            window.location.href = url
          } else {
            self.$MessageBox.alert(res.userMsg ? res.userMsg : res.msg)
          }
        }).always(function () {
          self.$Indicator.close()
        })
      },
      getAudioType () {
        const self = this
        self.$api.detail.getAuditType().then(res => {
          self.autoPassFlag = res.data.autoPassFlag
          if (!self.autoPassFlag) {
            self.$router.push('/detail/addition/?auditType=' + false)
          } else {
            self.$router.push('/detail/')
          }
          self.info = res.data.info
        })
      },
      skip () {
        const self = this
        self.getSignUrl()
      }
    }
  }
</script>
<style scoped>
  .bg {
    text-align: center;
    padding: 20px;
  }
  .bg img {
    width: 63%;
  }
  .tip {line-height: 50px;text-align: center;font-size: 18px;}
  .fill-btn {
    background:#04cab3;
  }
</style>